home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / HeadD.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  9.8 KB  |  349 lines

  1. class classes.enemy.HeadD
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var colorR;
  9.    var trans;
  10.    var colorTrans;
  11.    var f2;
  12.    var dir;
  13.    var axis;
  14.    var xDest;
  15.    var yDest;
  16.    var ep;
  17.    var oldDir;
  18.    var xMov = 0;
  19.    var yMov = 0;
  20.    var xMovT = 0;
  21.    var yMovT = 0;
  22.    var speedOrig = 8;
  23.    var speed = 8;
  24.    var xDestMet = false;
  25.    var yDestMet = false;
  26.    var c = 0;
  27.    var life = 3;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var nudging = false;
  32.    var hc = 0;
  33.    var power = 15;
  34.    var Name = "headD";
  35.    function HeadD(px, py, pmoveScript, pid)
  36.    {
  37.       this.x = px;
  38.       this.y = py;
  39.       this.moveScript = pmoveScript.slice();
  40.       this.id = pid;
  41.       _root.d = _root.d + 1;
  42.       this.clip = _root.attachMovie("headB","headD" + this.id + "Clip",_root.d + 50000);
  43.       this.clip._x = this.x;
  44.       this.clip._y = this.y;
  45.       this.speed *= _root.dif.speed;
  46.       this.speedOrig = this.speed;
  47.       this.life *= _root.dif.life;
  48.       this.speedVar();
  49.       this.colorR = -255;
  50.       this.trans = new flash.geom.Transform(this.clip);
  51.       this.colorTrans = new flash.geom.ColorTransform(0,0,0,1,this.colorR,this.colorR,this.colorR,0);
  52.       this.trans.colorTransform = this.colorTrans;
  53.       this.parseMoveScript();
  54.       _root.stats.created = _root.stats.created + 1;
  55.    }
  56.    function nudge(pxA, pyA, pscale)
  57.    {
  58.       this.nc = 0;
  59.       this.nudging = true;
  60.       var _loc2_ = pscale / 100;
  61.       this.xA = pxA * _loc2_;
  62.       this.yA = pyA * _loc2_;
  63.    }
  64.    function speedVar()
  65.    {
  66.       if(random(3) == 1)
  67.       {
  68.          this.speed *= _root.randRange2(0.9998,1.0002);
  69.       }
  70.    }
  71.    function bombed(num)
  72.    {
  73.       this.f2 = "death";
  74.    }
  75.    function parseMoveScript()
  76.    {
  77.       this.dir = this.moveScript[0];
  78.       if(this.dir == "break")
  79.       {
  80.          delete this.moveScript;
  81.          this[this.axis + "MovT"] = 0;
  82.          this.f2 = "wander";
  83.          if(random(10) > 2)
  84.          {
  85.             this.dir = _root.getDir(this.x,this.y);
  86.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  87.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  88.             this.speedVar();
  89.          }
  90.          else
  91.          {
  92.             this.axis = random(10) <= 4 ? "y" : "x";
  93.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  94.             this.getDirString();
  95.          }
  96.       }
  97.       else
  98.       {
  99.          this[this.axis + "MovT"] = 0;
  100.          this.f2 = "gotoXYDest";
  101.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  102.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  103.          this.speedVar();
  104.          if(this.dir == "L" || this.dir == "U")
  105.          {
  106.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  107.          }
  108.          else
  109.          {
  110.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  111.          }
  112.          this.moveScript.splice(0,2);
  113.       }
  114.    }
  115.    function gotoXYDest()
  116.    {
  117.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  118.       {
  119.          if(this.axis == "x")
  120.          {
  121.             this.x = this.xDest;
  122.          }
  123.          else
  124.          {
  125.             this.y = this.yDest;
  126.          }
  127.          this.parseMoveScript();
  128.       }
  129.    }
  130.    function getDirString()
  131.    {
  132.       if(this.xMovT < -1)
  133.       {
  134.          this.dir = "L";
  135.       }
  136.       else if(this.xMovT > 1)
  137.       {
  138.          this.dir = "R";
  139.       }
  140.       else if(this.yMovT > 1)
  141.       {
  142.          this.dir = "D";
  143.       }
  144.       else if(this.yMovT < -1)
  145.       {
  146.          this.dir = "U";
  147.       }
  148.    }
  149.    function wander()
  150.    {
  151.       if(random(100) > 70 || (this.x > 950 || this.x < 50 || this.y < 50 || this.y > 550))
  152.       {
  153.          if(random(20) > 18)
  154.          {
  155.             this[this.axis + "MovT"] = 0;
  156.             this.f2 = "wait";
  157.             this.c = 0;
  158.             this.ep = _root.randRange(30,120);
  159.             this.ep *= 1 / _root.dif.speed;
  160.          }
  161.          else if(random(10) > 1)
  162.          {
  163.             this.dir = _root.getDir(this.x,this.y);
  164.             this[this.axis + "MovT"] = 0;
  165.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  166.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  167.             this.speedVar();
  168.          }
  169.          else
  170.          {
  171.             this[this.axis + "MovT"] = 0;
  172.             this.axis = random(10) <= 4 ? "y" : "x";
  173.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  174.             this.getDirString();
  175.          }
  176.       }
  177.    }
  178.    function wait()
  179.    {
  180.       this.c = this.c + 1;
  181.       if(this.c >= this.ep)
  182.       {
  183.          this.f2 = "wander";
  184.          if(random(10) > 2)
  185.          {
  186.             this.dir = _root.getDir(this.x,this.y);
  187.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  188.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  189.             this.speedVar();
  190.          }
  191.          else
  192.          {
  193.             this.axis = random(10) <= 4 ? "y" : "x";
  194.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  195.             this.getDirString();
  196.          }
  197.       }
  198.       if(random(100) > 95)
  199.       {
  200.          var _loc3_ = ["L","R","F"];
  201.          this.dir = _loc3_[random(_loc3_.length)];
  202.       }
  203.    }
  204.    function attacking()
  205.    {
  206.    }
  207.    function death()
  208.    {
  209.       _root.stats.destroyed = _root.stats.destroyed + 1;
  210.       _root.stats.score += 750;
  211.       _root.powerUpB(this.x,this.y,80,"tripleTwistLaser",4);
  212.       _root.createExploD([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(60,80),_root.randRange(75,100)]);
  213.       var _loc3_ = 0;
  214.       var _loc4_ = random(3);
  215.       while(_loc3_ < _loc4_)
  216.       {
  217.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"headB","",false,true]);
  218.          _loc3_ = _loc3_ + 1;
  219.       }
  220.       _root.audio.playLevel4("headX" + (random(3) + 1),_root.randRange(15,25));
  221.       _root.removeChar("headD" + this.id);
  222.       this.f2 = "";
  223.    }
  224.    function death2()
  225.    {
  226.       _root.removeChar("headD" + this.id);
  227.       this.f2 = "";
  228.    }
  229.    function main()
  230.    {
  231.       this[this.f2]();
  232.       if(this.oldDir != this.dir)
  233.       {
  234.          if(this.oldDir == undefined || this.dir == "F")
  235.          {
  236.             this.clip.body.eyes.gotoAndStop(this.dir);
  237.          }
  238.          else if(this.dir == "U" || this.dir == "D")
  239.          {
  240.             this.clip.body.eyes.gotoAndStop(this.oldDir);
  241.          }
  242.          else if(random(3) > 0)
  243.          {
  244.             if(this.dir == "R")
  245.             {
  246.                this.clip.body.eyes.gotoAndPlay("LtoR");
  247.             }
  248.             else
  249.             {
  250.                this.clip.body.eyes.gotoAndPlay("RtoL");
  251.             }
  252.          }
  253.          else
  254.          {
  255.             this.clip.body.eyes.gotoAndPlay("spin" + this.dir);
  256.          }
  257.       }
  258.       this.oldDir = this.dir;
  259.       if(this.nudging)
  260.       {
  261.          this.xA *= 0.5;
  262.          this.yA *= 0.5;
  263.          this.nc = this.nc + 1;
  264.          var _loc8_ = 255 - this.nc * 17;
  265.          this.colorTrans.redOffset = _loc8_ / 2;
  266.          this.trans.colorTransform = this.colorTrans;
  267.          if(this.nc == 15)
  268.          {
  269.             this.xA = this.yA = 0;
  270.             this.nudging = false;
  271.             this.colorTrans.redOffset = this.colorR;
  272.             this.trans.colorTransform = this.colorTrans;
  273.          }
  274.       }
  275.       var _loc4_ = 0;
  276.       var _loc7_ = _root.broShots.length;
  277.       while(_loc4_ < _loc7_)
  278.       {
  279.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  280.          if(this.clip.hitTest(_root[_loc6_]))
  281.          {
  282.             var _loc3_ = _root.broShots[_loc4_];
  283.             var _loc5_ = this.life;
  284.             this.life -= _root[_loc3_].power;
  285.             if(this.life < 1)
  286.             {
  287.                this.f2 = "death";
  288.             }
  289.             else
  290.             {
  291.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  292.                _root.audio.playLevel4("headHit" + (random(4) + 1),_root.randRange(18,28));
  293.                this[this.axis + "MovT"] = 0;
  294.                this.axis = random(10) <= 4 ? "y" : "x";
  295.                this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  296.                this.getDirString();
  297.             }
  298.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  299.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  300.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  301.             _root[_loc3_].hit(_loc5_);
  302.             break;
  303.          }
  304.          _loc4_ = _loc4_ + 1;
  305.       }
  306.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  307.       {
  308.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  309.          this.f2 = "death";
  310.       }
  311.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  312.       {
  313.          this.f2 = "death2";
  314.       }
  315.       if(this.xMovT < this.xMov)
  316.       {
  317.          this.xMov -= 0.3;
  318.       }
  319.       else if(this.xMovT > this.xMov)
  320.       {
  321.          this.xMov += 0.3;
  322.       }
  323.       else
  324.       {
  325.          this.xMov = this.xMovT;
  326.       }
  327.       if(this.yMovT < this.yMov)
  328.       {
  329.          this.yMov -= 0.3;
  330.       }
  331.       else if(this.yMovT > this.yMov)
  332.       {
  333.          this.yMov += 0.3;
  334.       }
  335.       else
  336.       {
  337.          this.yMov = this.yMovT;
  338.       }
  339.       if(random(100) > 98)
  340.       {
  341.          this.clip.body.eyes.clip.gotoAndPlay("blink");
  342.       }
  343.       this.x += this.xMov + this.xA;
  344.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.1);
  345.       this.clip._x = this.x;
  346.       this.clip._y = this.y;
  347.    }
  348. }
  349.